class Bird {
  float r;
  float health;
  Body body;
  PImage img;
  
  Bird(float x, float y) {
    this.r = 12;
    this.health = 500;
    this.img = loadImage("bird.png");
    BodyDef bd = new BodyDef();
    // Set its position
    bd.position = box2d.coordPixelsToWorld(x, y);
    bd.type = BodyType.DYNAMIC;
    bd.angularDamping = 3;
    this.body = box2d.world.createBody(bd);

    // Make the body's shape a circle
    CircleShape cs = new CircleShape();
    cs.m_radius = box2d.scalarPixelsToWorld(r);
    
    FixtureDef fd = new FixtureDef();
    fd.shape = cs;
    // Parameters that affect physics
    fd.density = 1;
    fd.friction = 1000;
    fd.restitution = 0.3;
    
    // Attach fixture to body
    this.body.createFixture(fd);
    this.body.setUserData(this);
  }
  
  void draw() {
    // We look at each body and get its screen position
    Vec2 pos = box2d.getBodyPixelCoord(this.body);
    // Get its angle of rotation
    float a = this.body.getAngle();
    pushMatrix();
    translate(pos.x, pos.y);
    rotate(-a);
    image(this.img, 0, 0, this.r * 2 + 2, this.r * 2 + 2);
    popMatrix();
  }
  
  boolean isOutOfHealth() {
    return this.health <= 0;
  }
  
  void destroy() {
    box2d.destroyBody(this.body);
  }
}
